namespace Sustainalytics.Portfolios.BL.Validators
{
    using System.Collections.Generic;
    using System.Linq;

    using Sustainalytics.Entities;
    using Sustainalytics.Utils;
    using Sustainalytics.Utils.Validation.Interfaces;

    public class PortfolioReadValidator : IValidator<Portfolio, PortfolioUserClaims>
    {
        public bool IsValid(Portfolio portfolio, PortfolioUserClaims userClaims)
        {
            return portfolio.AddedByUserId == userClaims.UserId
                    || (portfolio.SharingStatus == PortfolioSharingStatus.Shared &&
                         portfolio.AccountIds.Contains(userClaims.AccountId))
                         || (portfolio.IsAutomatic && portfolio.IsReadonly);
        }

        public ICollection<string> BrokenRules(Portfolio entity, PortfolioUserClaims entityAgainstValidate)
        {
            return new List<string>();
        }
    }
}